package com.samphanie.auiu.auth.service.impl;

import com.samphanie.auiu.auth.service.IRoleService;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Service;

import java.util.stream.Collectors;

import static com.samphanie.auiu.common.constants.AuiuConstants.ROLE_ADMIN;
import static com.samphanie.auiu.common.constants.AuiuConstants.ROLE_STAFF;

/**
 * @author ZSY
 * @email 1451691457@qq.com
 */
@Service
@RequiredArgsConstructor
public class RoleHierarchyService {

    private final IRoleService roleService;

    public String getRoleHierarchyExpr() {
        val roles = roleService.list();
        return roles.stream()
                .flatMap(role -> role.getPermissions().stream()
                        .map(permission -> role.getRoleName() + " > " + permission.getAuthority() + " "))
                .collect(Collectors.joining(" ", ROLE_ADMIN + " > " + ROLE_STAFF + " ", ""));
    }

}
